package org.jeecg.modules.business.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.jeecg.common.util.TokenUtils;
import org.jeecg.modules.business.entity.BusMeetingRoomScheduleDetail;
import org.jeecg.modules.business.mapper.BusMeetingRoomScheduleDetailMapper;
import org.jeecg.modules.business.service.IBusMeetingRoomScheduleDetailService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 会议室预定档期表 服务实现类
 * </p>
 *
 * @author fendo
 * @since 2023-03-15
 */
@Service
public class BusMeetingRoomScheduleDetailServiceImpl extends ServiceImpl<BusMeetingRoomScheduleDetailMapper, BusMeetingRoomScheduleDetail> implements IBusMeetingRoomScheduleDetailService {

    @Resource
    private BusMeetingRoomScheduleDetailMapper scheduleDetailMapper;


    /**
     * 批量保存 复用接口
     * @param detailList
     * @return
     */
    public boolean saveBatchDetail(List<BusMeetingRoomScheduleDetail> detailList){
        if(CollectionUtil.isEmpty(detailList)) return false;
        return saveBatch(detailList);
    }


    public List<BusMeetingRoomScheduleDetail> fetchByRoomIds(List<String> roomIds){
        if(CollectionUtil.isEmpty(roomIds)) return new ArrayList<>();
        return scheduleDetailMapper.selectList(Wrappers.<BusMeetingRoomScheduleDetail>lambdaQuery().in(BusMeetingRoomScheduleDetail::getMeetingRoomId,roomIds));
    }



    public List<BusMeetingRoomScheduleDetail> fetchByDateRange(LocalDateTime startDate, LocalDateTime endDate,String hotelId,List<String> meetRoomIds){
        if(CollectionUtil.isEmpty(meetRoomIds)) return new ArrayList<>();
        QueryWrapper<BusMeetingRoomScheduleDetail> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(BusMeetingRoomScheduleDetail.TENANT_ID, TokenUtils.currentTenantId());
        queryWrapper.eq(BusMeetingRoomScheduleDetail.HOTEL_ID,hotelId);
        queryWrapper.between(BusMeetingRoomScheduleDetail.MEETING_DATE, startDate,endDate);
        queryWrapper.in(BusMeetingRoomScheduleDetail.MEETING_ROOM_ID,meetRoomIds);

        return scheduleDetailMapper.selectList(queryWrapper);
    }
}
